//
//  HWRealNameAuthenticationController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/28.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWRealNameAuthenticationController.h"
#import "HWShimingrenzhengCell.h"
#import "HWAES128.h"
#import "HWshingmingrenzhimiaoshuView.h"
#define    wholeProjectBlackFontColor  RGB(51,51,51)

@interface HWRealNameAuthenticationController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
@property(strong,nonatomic)UITableView *mainaTableVie;
@property(strong,nonatomic)NSArray *dataArr;
@property(strong,nonatomic)NSArray *placeholderArr;
@property(strong,nonatomic)UIView *lowerPartView;
@property(strong,nonatomic)UIView *footerview;
@property(strong,nonatomic)UIImageView *zhengmianImageView;
@property(strong,nonatomic)UIImageView *fanmianImageview;
@property(strong,nonatomic)NSString *panduanStr;

//最新的控件
@property(strong,nonatomic) UIImageView *shimingbeijingImageView;

@property(strong,nonatomic) HWshingmingrenzhimiaoshuView *shipingzhi;


@end

@implementation HWRealNameAuthenticationController


-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
       // _mainaTableVie.backgroundColor = RGB(241, 242, 244);
        
    }
    return   _mainaTableVie ;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  //     [self setupdata];
    //   [self setupUI];
     [self addLowerPartView];
     //  [self addheaderView];
    
       [self zuixingdeUI];
    
}



//最新设置UI 
- (void)zuixingdeUI {
    
    
    self.navigationItem.title = @"实名认证";
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"实名认证"];
    
    
    self.view.backgroundColor = RGB(247, 247, 247);
    self.shimingbeijingImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, NavBarHeight+10 , kScreenW-40, 104)];
    self.shimingbeijingImageView.image = [UIImage imageNamed:@"shenfenrenzhengbeijing"];
    [self.view addSubview: self.shimingbeijingImageView];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(28,0, kScreenW-40-56, 104)];
                 //     nameLabel.text = fanlilistArr[i];
          //  nameLabel.backgroundColor =  RGB(248, 119, 6);
           nameLabel.backgroundColor = [UIColor clearColor];
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:19.5];
            nameLabel.textColor = RGB(255, 255, 255);
           nameLabel.numberOfLines = 0;
       //     nameLabel.layer.cornerRadius = 8;
       //     nameLabel.layer.masksToBounds = YES;
       nameLabel.text = @"为响应国家法律法规相关要求\n手机游戏用户需要进行实名认证";
    nameLabel.text  = [HWjianzhiduiObject keylocalization:@"为响应国家法律法规相关要求\n手机游戏用户需要进行实名认证"];
    
     [self.shimingbeijingImageView  addSubview:nameLabel];
    
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = 10 - (nameLabel.font.lineHeight - nameLabel.font.pointSize);
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
    nameLabel.attributedText = [[NSAttributedString alloc] initWithString:nameLabel.text attributes:attributes];
    
    nameLabel.textAlignment = NSTextAlignmentCenter;
    
    
    
    self.shipingzhi = [[NSBundle mainBundle]loadNibNamed:@"HWshingmingrenzhimiaoshuView" owner:nil options:nil].firstObject;
    self.shipingzhi.frame = CGRectMake(0, self.shimingbeijingImageView.bottom, kScreenW, 180);
    [self.view  addSubview: self.shipingzhi];
    
       
    
    
    
    
    
    
    
    
}

- (void)setupdata {
    
    self.dataArr = @[@"真实姓名",@"证件类型",@"证件号码"];
    self.placeholderArr = @[@"请填写真实姓名",@"",@"请填写身份证号码"];
    
}

// 设置UI
- (void)setupUI {
    
    
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"实名认证";
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"实名认证"];
    
    [self.view addSubview:self.mainaTableVie];
    
    
}





// 添加低部UIview
- (void)addLowerPartView {
    
    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-10-44-20-17-CF_TabbarSafeBottomMargin, kScreenW, 10+44+20+17+CF_TabbarSafeBottomMargin)];
    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
    self.lowerPartView.backgroundColor = [UIColor whiteColor];
    self.lowerPartView.backgroundColor = RGB(247, 247, 247);
    [self.view addSubview:self.lowerPartView];
    
    
    
    NSString *tijiao = [NSString stringWithFormat:@"提交"];
    
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(20, 10, kScreenW-20*2, 44) Title:tijiao Image:nil Font:13 Color:RGB(255, 255, 155) Target:self Selector:@selector(buttonTap)];
    butt.backgroundColor = blueBackgroundBT;
    butt.layer.cornerRadius = 18;
    butt.layer.masksToBounds = YES;
    butt.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView:butt];
    
    [self.lowerPartView addSubview:butt];
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,butt.bottom+10, kScreenW-40, 17)];
                   //     nameLabel.text = fanlilistArr[i];
            //  nameLabel.backgroundColor =  RGB(248, 119, 6);
             nameLabel.backgroundColor = [UIColor clearColor];
              nameLabel.textAlignment = NSTextAlignmentCenter;
              nameLabel.font = [UIFont systemFontOfSize:13];
              nameLabel.textColor = RGB(136, 136, 136);
             nameLabel.numberOfLines = 0;
      
         //     nameLabel.layer.cornerRadius = 8;
         //     nameLabel.layer.masksToBounds = YES;
              nameLabel.text = @"实名认证仅做防沉迷功能，对账号安全没有任何影响";
    nameLabel.text = [HWjianzhiduiObject keylocalization:@"实名认证仅做防沉迷功能，对账号安全没有任何影响"];
    
    [self.lowerPartView addSubview:nameLabel];
    
    
    
    
   


    
}

// 添加headerView
- (void)addheaderView {
    
    self.footerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 173+40)];
    self.footerview.backgroundColor = [UIColor whiteColor];
    
    
    
    self.mainaTableVie.tableFooterView = self.footerview;

    UILabel   *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, 200, 40)];
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.textColor = RGB(51, 51, 51);
    nameLabel.text = @"上传证件照";
    nameLabel.hidden = YES;
    [self.footerview addSubview:nameLabel];
    
    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(12, 40, (kScreenW-12*3)/2, 173)];
    view1.backgroundColor = RGB(233, 241, 255);
    view1.layer.cornerRadius = 6;
    view1.layer.masksToBounds = YES;
    [self.footerview addSubview:view1];
    view1.hidden = YES;
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(((kScreenW-12*3)/2-42)/2, 54, 42, 32)];
    imageView1.image = [UIImage imageNamed:@"p_camera"];
    
    imageView1.userInteractionEnabled = YES;
    [view1  addSubview:imageView1];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1)];
    [imageView1 addGestureRecognizer:tap1];
    
     UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView1.bottom+37, (kScreenW-12*3)/2, 14)];
    label1.textColor = RGB(153, 153, 153);
    label1.textAlignment =  NSTextAlignmentCenter;
    label1.text = @"请添加正面照";
    [view1 addSubview:label1];
    
    
    self.zhengmianImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, (kScreenW-12*3)/2, 173)];
    self.zhengmianImageView.hidden = YES;
    [view1 addSubview: self.zhengmianImageView];
    
    
    
    
    
    
    
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake( (kScreenW-12*3)/2+12*2, 40, (kScreenW-12*3)/2, 173)];
      view2.backgroundColor = RGB(233, 241, 255);
      view2.layer.cornerRadius = 6;
      view2.layer.masksToBounds = YES;
      [self.footerview addSubview:view2];
    
    view2.hidden = YES;
    
    
     UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(((kScreenW-12*3)/2-42)/2, 54, 42, 32)];
     imageView2.image = [UIImage imageNamed:@"p_camera"];
    imageView2.userInteractionEnabled = YES;
     [view2  addSubview:imageView2];
    
     UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianjitap2)];
      [imageView2 addGestureRecognizer:tap2];
     
     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView2.bottom+37, (kScreenW-12*3)/2, 14)];
     label2.textColor = RGB(153, 153, 153);
     label2.textAlignment =  NSTextAlignmentCenter;
     label2.text = @"请添加反面照";
     [view2 addSubview:label2];
    
     self.fanmianImageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, (kScreenW-12*3)/2, 173)];
     self.fanmianImageview.hidden = YES;
     [view2 addSubview: self.fanmianImageview];
    
    

    
}


#pragma mark --------  点击事件

- (void)tap1 {
    
    DLog(@"正面");
    self.panduanStr = @"1";
    
    [self setUPUserImage];
    
}

- (void)dianjitap2 {
      self.panduanStr = @"2";
     DLog(@"反面");
    [self setUPUserImage];
    
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    
    return YES;
    
}


#pragma mark ------ 点击保存按钮
- (void)buttonTap {
    
    DLog(@"保存");
    
//    NSIndexPath *index1 = [NSIndexPath indexPathForRow:0 inSection:0];
//      HWShimingrenzhengCell *cell1 = [self.mainaTableVie cellForRowAtIndexPath:index1];
//
//
//       NSIndexPath *index3 = [NSIndexPath indexPathForRow:2 inSection:0];
//       HWShimingrenzhengCell *cell3 = [self.mainaTableVie cellForRowAtIndexPath:index3];
//
      
      if (!(self.shipingzhi.xingmingtextFeild.text.length > 0)) {
          
          [MBProgressHUD showError:@"真实姓名不能为空"];
          return;

      } else if ( !(self.shipingzhi.shenfenzhengTextField.text.length > 0)) {
          
           [MBProgressHUD showError:@"身份证不能为空"];
          return;
          
       }
      
//      if ( ![WMUtil   validateIdentityCard:cell3.nameTextField.text]) {
//          [MBProgressHUD showError:@"请输入正确的身份证号"];
//                return;
//      }
//
     
      
    
          NSString *userID = [HWLocallyStoredData getLoginUserID];
             NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
             NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
             NSString *signMD5 = [WMUtil md5HexDigest:sign];
             
             NSDictionary *signDic = @{
                 @"name" : self.shipingzhi.xingmingtextFeild.text,
                 @"idcard" : self.shipingzhi.shenfenzhengTextField.text,
                 
               
                                       };
             NSString *jsonStr = [self convertToJsonData:signDic];
             NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
       
       
       
       
             NSDictionary *parametes = @{
                                        @"ct" :  @"app",
                                        @"ac" : @"re_info",
                                        @"ios" : @"1",
                                        @"uid" :userID,
                                        @"t" :tStr,
                                        @"sign": signMD5,
                                         @"value" : encryStr,
                                        };
       
       
       
       
       
            
        //    [MBProgressHUD show:@"正在绑定邮箱"];
       
       
        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
           
                   NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                   //   [MBProgressHUD hideHUD];
                      
                      
                      if ([codeStr intValue] == 1) {
                        
                    
                        // [MBProgressHUD  showSuccess:response[@"message"]];
                          //[self.navigationController popViewControllerAnimated:YES];
                          
                       //   [self.navigationController popViewControllerAnimated:YES];
                          
                          [self.navigationController popViewControllerAnimated:YES];
                          
                          
                    
             
                         

                      } else {
                       
                           [MBProgressHUD  showError:response[@"message"]];
                          
                      }
                      NSLog(@"%@",response);
                      
           
       } failure:^(NSString *error) {

           [MBProgressHUD  showError:@"查询失败"];
       } ];
      
    
    
    
    
    
    
//    NSIndexPath *index1 = [NSIndexPath indexPathForRow:0 inSection:0];
//    HWShimingrenzhengCell *cell1 = [self.mainaTableVie cellForRowAtIndexPath:index1];
//
//
//     NSIndexPath *index3 = [NSIndexPath indexPathForRow:2 inSection:0];
//     HWShimingrenzhengCell *cell3 = [self.mainaTableVie cellForRowAtIndexPath:index3];
//
//
//    if (!(cell1.nameTextField.text.length > 0)) {
//
//        [MBProgressHUD showError:@"真实姓名不能为空"];
//        return;
//
//    } else if ( !(cell3.nameTextField.text.length > 0)) {
//
//         [MBProgressHUD showError:@"身份证不能为空"];
//        return;
//
//     }
//
//    if ( ![WMUtil   validateIdentityCard:cell3.nameTextField.text]) {
//        [MBProgressHUD showError:@"请输入正确的身份证号"];
//              return;
//    }
//
//
//
//
//        NSString *userID = [HWLocallyStoredData getLoginUserID];
//           NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//           NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
//           NSString *signMD5 = [WMUtil md5HexDigest:sign];
//
//           NSDictionary *signDic = @{
//               @"name" : cell1.nameTextField.text,
//               @"idcard" : cell3.nameTextField.text,
//
//
//                                     };
//           NSString *jsonStr = [self convertToJsonData:signDic];
//           NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
//
//
//
//
//           NSDictionary *parametes = @{
//                                      @"ct" :  @"app",
//                                      @"ac" : @"re_info",
//                                      @"ios" : @"1",
//                                      @"uid" :userID,
//                                      @"t" :tStr,
//                                      @"sign": signMD5,
//                                       @"value" : encryStr,
//                                      };
//
//
//
//
//
//
//      //    [MBProgressHUD show:@"正在绑定邮箱"];
//
//
//      [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
//
//                 NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//                 //   [MBProgressHUD hideHUD];
//
//
//                    if ([codeStr intValue] == 1) {
//
//
//                      // [MBProgressHUD  showSuccess:response[@"message"]];
//                        //[self.navigationController popViewControllerAnimated:YES];
//
//                     //   [self.navigationController popViewControllerAnimated:YES];
//
//                        [self.navigationController popViewControllerAnimated:YES];
//
//
//
//
//
//
//                    } else {
//
//                         [MBProgressHUD  showError:response[@"message"]];
//
//                    }
//                    NSLog(@"%@",response);
//
//
//     } failure:^(NSString *error) {
//
//         [MBProgressHUD  showError:@"查询失败"];
//     } ];
//
    
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {
    static NSString *cellID = @"cellID";
    HWShimingrenzhengCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[HWShimingrenzhengCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
       
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    
    
    cell.nameLabel.text = self.dataArr[indexPath.row];
       NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.placeholderArr[indexPath.row] attributes:
            @{NSForegroundColorAttributeName:RGB(153, 153, 153),
              NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
            ];
    cell.nameTextField.attributedPlaceholder  = attrString;
    cell.nameTextField.delegate  = self;
    
    if (indexPath.row == 1) {
        cell.icoimageView.hidden = YES;
        cell.nameTextField.hidden = YES;
         cell.shengFenLabel.hidden =  NO;
        
    } else {
        
        cell.icoimageView.hidden = NO;
        cell.nameTextField.hidden = NO;
        cell.shengFenLabel.hidden =  YES;
        
    }
    
  
    return  cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  40;
    
}



#pragma  mark  ------------  点击更换头像
- (void)setUPUserImage {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //
        [self picturesImage];
    }];
    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self photoAlbumImage];
    }];
    
    // KVC 改变颜色
    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
    }];
    // KVC 改变颜色
    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];

    [alert addAction:videoAction];
    [alert addAction:gifAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];

    
}

//点击拍照
- (void)picturesImage {
    
  
    

    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    
    if (result) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePicker animated:YES completion:nil];
        
        
    }else{
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
//        [alert show];
        
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    
        }];
        [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
        UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
        }];
        // KVC 改变颜色
        [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
        [alert addAction:videoAction];
        [alert addAction:gifAction];
        [self presentViewController:alert animated:YES completion:nil];
//
      
        
    }

    
}


//点击相册
- (void)photoAlbumImage {

    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
    if (result) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //                        [self presentModalViewController:imagePicker animated:YES];
        [self presentViewController:imagePicker animated:YES completion:nil];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
        [alert show];
    }
    
    
}


#pragma  mark ---------  UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
     UIImage *userImage = [self fixOrientation:(UIImage *)info[UIImagePickerControllerEditedImage]];
    // UIImagePickerControllerOriginalImage
   
    // 图片缩放
    userImage = [self scaleImage:userImage toScale:0.3];
    
    //    照片上传
    // [self upDateHeadIcon:userImage];
    //保存图片 保存到沙河
    //   [self saveImage:userImage name:@"touxiang"];
    
    // QrCodeableViewCell *qrCodCell = [tableView dequeueReusableCellWithIdentifier:qrCodID];
    
//    NSIndexPath *inde = [NSIndexPath indexPathForRow:0 inSection:0];
//    IconInformationCell *iconcell =   (IconInformationCell *)[self.informationTableview cellForRowAtIndexPath:inde];
//    iconcell.IconImageView.image = userImage;
    
    
    if ([self.panduanStr isEqualToString:@"1"]) {
        self.zhengmianImageView.hidden = NO;
          self.zhengmianImageView.image = userImage;
    } else {
        
        self.fanmianImageview.hidden = NO;
        self.fanmianImageview.image = userImage;
        
        
        
    }
   
    
    //往配图相册view里面添加图片
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
//    //    修正照片方向(手机转90度方向拍照)
//    UIImage *userImage = [self fixOrientation:[editingInfo objectForKey:@"UIImagePickerControllerOriginalImage"]];
//
//    // 图片缩放
//    userImage = [self scaleImage:userImage toScale:0.3];
//
//    //    照片上传
//   // [self upDateHeadIcon:userImage];
//    //保存图片 保存到沙河
//  //   [self saveImage:userImage name:@"touxiang"];
//
//    //往配图相册view里面添加图片
//    [picker dismissViewControllerAnimated:YES completion:nil];
//}


//修正照片方向(手机转90度方向拍照)
- (UIImage *)fixOrientation:(UIImage *)aImage {
    
    // No-op if the orientation is already correct
    if (aImage.imageOrientation == UIImageOrientationUp)
        return aImage;
    
    // We need to calculate the proper transformation to make the image upright.
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationDown:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformRotate(transform, M_PI_2);
            break;
            
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
            transform = CGAffineTransformRotate(transform, -M_PI_2);
            break;
        default:
            break;
    }
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationUpMirrored:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
            
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
        default:
            break;
    }
    
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
                                             CGImageGetColorSpace(aImage.CGImage),
                                             CGImageGetBitmapInfo(aImage.CGImage));
    CGContextConcatCTM(ctx, transform);
    switch (aImage.imageOrientation) {
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            // Grr...
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
            break;
            
        default:
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
            break;
    }
    
    // And now we just create a new UIImage from the drawing context
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage *img = [UIImage imageWithCGImage:cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return img;
}

//缩放图片
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
 UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSLog(@"%@",NSStringFromCGSize(scaledImage.size));
    return scaledImage;
}

//保存照片到沙盒路径(保存)
- (void)saveImage:(UIImage *)image name:(NSString *)iconName
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    //写入文件
    NSString *icomImage = iconName;
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", icomImage]];
    // 保存文件的名称
    //    [[self getDataByImage:image] writeToFile:filePath atomically:YES];
    [UIImagePNGRepresentation(image) writeToFile: filePath  atomically:YES];
}

//上传图片
- (void)upDateHeadIcon:(UIImage *)photo
{
    if (photo == nil) {
        return;
    }
    
    
}




-(NSString *)convertToJsonData:(NSDictionary *)dict {
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        NSLog(@"%@",error);
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
    
}





@end




#pragma mark ---------  以前的代码



//#import "HWRealNameAuthenticationController.h"
//#import "HWShimingrenzhengCell.h"
//
//#import "HWAES128.h"
//#define    wholeProjectBlackFontColor  RGB(51,51,51)
//
//@interface HWRealNameAuthenticationController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
//@property(strong,nonatomic)UITableView *mainaTableVie;
//@property(strong,nonatomic)NSArray *dataArr;
//@property(strong,nonatomic)NSArray *placeholderArr;
//@property(strong,nonatomic)UIView *lowerPartView;
//@property(strong,nonatomic)UIView *footerview;
//@property(strong,nonatomic)UIImageView *zhengmianImageView;
//@property(strong,nonatomic)UIImageView *fanmianImageview;
//@property(strong,nonatomic)NSString *panduanStr;
//
////
//@end
//
//@implementation HWRealNameAuthenticationController
//
//
//-(UITableView *)mainaTableVie {
//
//    if  (_mainaTableVie == nil) {
//
//        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
//        _mainaTableVie.delegate = self;
//        _mainaTableVie.dataSource = self;
//        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
//
//        _mainaTableVie.backgroundColor = [UIColor whiteColor];
//       // _mainaTableVie.backgroundColor = RGB(241, 242, 244);
//
//    }
//    return   _mainaTableVie ;
//
//}
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    // Do any additional setup after loading the view.
//      [self setupdata];
//      [self setupUI];
//     [self addLowerPartView];
//      [self addheaderView];
//
//}
//
//
//
////最新设置UI
//- (void)zuixingdeUI {
//
//
//
//
//
//
//
//}
//
//- (void)setupdata {
//
//    self.dataArr = @[@"真实姓名",@"证件类型",@"证件号码"];
//    self.placeholderArr = @[@"请填写真实姓名",@"",@"请填写身份证号码"];
//
//}
//
//// 设置UI
//- (void)setupUI {
//
//
//
//
//    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationItem.title = @"实名认证";
//    [self.view addSubview:self.mainaTableVie];
//
//
//}
//
//
//
//
//
//// 添加低部UIview
//- (void)addLowerPartView {
//
//    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-44-CF_TabbarSafeBottomMargin, kScreenW, 44+CF_TabbarSafeBottomMargin)];
//    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
//    self.lowerPartView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.lowerPartView];
//
//    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(15, 0, kScreenW-15*2, 36) Title:@"保存" Image:nil Font:13 Color:RGB(255, 255, 155) Target:self Selector:@selector(buttonTap)];
//    butt.backgroundColor = blueBackgroundBT;
//    butt.layer.cornerRadius = 18;
//    butt.layer.masksToBounds = YES;
//    butt.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView:butt];
//
//    [self.lowerPartView addSubview:butt];
//
//
//
//
//
//}
//
//// 添加headerView
//- (void)addheaderView {
//
//    self.footerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 173+40)];
//    self.footerview.backgroundColor = [UIColor whiteColor];
//
//
//
//    self.mainaTableVie.tableFooterView = self.footerview;
//
//    UILabel   *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, 200, 40)];
//    nameLabel.font = [UIFont systemFontOfSize:14];
//    nameLabel.textColor = RGB(51, 51, 51);
//    nameLabel.text = @"上传证件照";
//    nameLabel.hidden = YES;
//    [self.footerview addSubview:nameLabel];
//
//
//
//    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(12, 40, (kScreenW-12*3)/2, 173)];
//    view1.backgroundColor = RGB(233, 241, 255);
//    view1.layer.cornerRadius = 6;
//    view1.layer.masksToBounds = YES;
//    [self.footerview addSubview:view1];
//    view1.hidden = YES;
//    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(((kScreenW-12*3)/2-42)/2, 54, 42, 32)];
//    imageView1.image = [UIImage imageNamed:@"p_camera"];
//
//    imageView1.userInteractionEnabled = YES;
//    [view1  addSubview:imageView1];
//    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1)];
//    [imageView1 addGestureRecognizer:tap1];
//
//     UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView1.bottom+37, (kScreenW-12*3)/2, 14)];
//    label1.textColor = RGB(153, 153, 153);
//    label1.textAlignment =  NSTextAlignmentCenter;
//    label1.text = @"请添加正面照";
//    [view1 addSubview:label1];
//
//
//    self.zhengmianImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, (kScreenW-12*3)/2, 173)];
//    self.zhengmianImageView.hidden = YES;
//    [view1 addSubview: self.zhengmianImageView];
//
//
//
//
//
//
//
//    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake( (kScreenW-12*3)/2+12*2, 40, (kScreenW-12*3)/2, 173)];
//      view2.backgroundColor = RGB(233, 241, 255);
//      view2.layer.cornerRadius = 6;
//      view2.layer.masksToBounds = YES;
//      [self.footerview addSubview:view2];
//
//    view2.hidden = YES;
//
//
//     UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(((kScreenW-12*3)/2-42)/2, 54, 42, 32)];
//     imageView2.image = [UIImage imageNamed:@"p_camera"];
//    imageView2.userInteractionEnabled = YES;
//     [view2  addSubview:imageView2];
//
//     UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianjitap2)];
//      [imageView2 addGestureRecognizer:tap2];
//
//     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView2.bottom+37, (kScreenW-12*3)/2, 14)];
//     label2.textColor = RGB(153, 153, 153);
//     label2.textAlignment =  NSTextAlignmentCenter;
//     label2.text = @"请添加反面照";
//     [view2 addSubview:label2];
//
//     self.fanmianImageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, (kScreenW-12*3)/2, 173)];
//     self.fanmianImageview.hidden = YES;
//     [view2 addSubview: self.fanmianImageview];
//
//
//
//
//}
//
//
//#pragma mark --------  点击事件
//
//- (void)tap1 {
//
//    DLog(@"正面");
//    self.panduanStr = @"1";
//
//    [self setUPUserImage];
//
//}
//
//- (void)dianjitap2 {
//      self.panduanStr = @"2";
//     DLog(@"反面");
//    [self setUPUserImage];
//
//
//}
//
//
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//
//    [self.view endEditing:YES];
//}
//
//
//- (BOOL)textFieldShouldReturn:(UITextField *)textField {
//
//    [textField resignFirstResponder];
//
//    return YES;
//
//}
//
//
//#pragma mark ------ 点击保存按钮
//- (void)buttonTap {
//
//    DLog(@"保存");
//
//    NSIndexPath *index1 = [NSIndexPath indexPathForRow:0 inSection:0];
//    HWShimingrenzhengCell *cell1 = [self.mainaTableVie cellForRowAtIndexPath:index1];
//
//
//     NSIndexPath *index3 = [NSIndexPath indexPathForRow:2 inSection:0];
//     HWShimingrenzhengCell *cell3 = [self.mainaTableVie cellForRowAtIndexPath:index3];
//
//
//    if (!(cell1.nameTextField.text.length > 0)) {
//
//        [MBProgressHUD showError:@"真实姓名不能为空"];
//        return;
//
//    } else if ( !(cell3.nameTextField.text.length > 0)) {
//
//         [MBProgressHUD showError:@"身份证不能为空"];
//        return;
//
//     }
//
//    if ( ![WMUtil   validateIdentityCard:cell3.nameTextField.text]) {
//        [MBProgressHUD showError:@"请输入正确的身份证号"];
//              return;
//    }
//
//
//
//
//        NSString *userID = [HWLocallyStoredData getLoginUserID];
//           NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//           NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
//           NSString *signMD5 = [WMUtil md5HexDigest:sign];
//
//           NSDictionary *signDic = @{
//               @"name" : cell1.nameTextField.text,
//               @"idcard" : cell3.nameTextField.text,
//
//
//                                     };
//           NSString *jsonStr = [self convertToJsonData:signDic];
//           NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
//
//
//
//
//           NSDictionary *parametes = @{
//                                      @"ct" :  @"app",
//                                      @"ac" : @"re_info",
//                                      @"ios" : @"1",
//                                      @"uid" :userID,
//                                      @"t" :tStr,
//                                      @"sign": signMD5,
//                                       @"value" : encryStr,
//                                      };
//
//
//
//
//
//
//      //    [MBProgressHUD show:@"正在绑定邮箱"];
//
//
//      [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
//
//                 NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//                 //   [MBProgressHUD hideHUD];
//
//
//                    if ([codeStr intValue] == 1) {
//
//
//                      // [MBProgressHUD  showSuccess:response[@"message"]];
//                        //[self.navigationController popViewControllerAnimated:YES];
//
//                     //   [self.navigationController popViewControllerAnimated:YES];
//
//                        [self.navigationController popViewControllerAnimated:YES];
//
//
//
//
//
//
//                    } else {
//
//                         [MBProgressHUD  showError:response[@"message"]];
//
//                    }
//                    NSLog(@"%@",response);
//
//
//     } failure:^(NSString *error) {
//
//         [MBProgressHUD  showError:@"查询失败"];
//     } ];
//
//
//
//
//}
//
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//
//    return 3;
//
//
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {
//    static NSString *cellID = @"cellID";
//    HWShimingrenzhengCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//    if (!cell) {
//        cell = [[HWShimingrenzhengCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
//
//    }
//
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor whiteColor];
//
//
//    cell.nameLabel.text = self.dataArr[indexPath.row];
//       NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.placeholderArr[indexPath.row] attributes:
//            @{NSForegroundColorAttributeName:RGB(153, 153, 153),
//              NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
//            ];
//    cell.nameTextField.attributedPlaceholder  = attrString;
//    cell.nameTextField.delegate  = self;
//
//    if (indexPath.row == 1) {
//        cell.icoimageView.hidden = YES;
//        cell.nameTextField.hidden = YES;
//         cell.shengFenLabel.hidden =  NO;
//
//    } else {
//
//        cell.icoimageView.hidden = NO;
//        cell.nameTextField.hidden = NO;
//        cell.shengFenLabel.hidden =  YES;
//
//    }
//
//
//    return  cell;
//
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//    return  40;
//
//}
//
//
//
//#pragma  mark  ------------  点击更换头像
//- (void)setUPUserImage {
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        //
//        [self picturesImage];
//    }];
//    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        [self photoAlbumImage];
//    }];
//
//    // KVC 改变颜色
//    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//
//    }];
//    // KVC 改变颜色
//    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    [alert addAction:videoAction];
//    [alert addAction:gifAction];
//    [alert addAction:cancelAction];
//    [self presentViewController:alert animated:YES completion:nil];
//
//
//}
//
////点击拍照
//- (void)picturesImage {
//
//
//
//
//    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
//
//    if (result) {
//        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//        imagePicker.delegate = self;
//        imagePicker.allowsEditing = YES;
//        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//        [self presentViewController:imagePicker animated:YES completion:nil];
//
//
//    }else{
////        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
////        [alert show];
//
//
//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//        }];
//        [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//        UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//        }];
//        // KVC 改变颜色
//        [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//        [alert addAction:videoAction];
//        [alert addAction:gifAction];
//        [self presentViewController:alert animated:YES completion:nil];
////
//
//
//    }
//
//
//}
//
//
////点击相册
//- (void)photoAlbumImage {
//
//    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
//    if (result) {
//        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//        imagePicker.delegate = self;
//        imagePicker.allowsEditing = YES;
//        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//        //                        [self presentModalViewController:imagePicker animated:YES];
//        [self presentViewController:imagePicker animated:YES completion:nil];
//    }else{
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
//        [alert show];
//    }
//
//
//}
//
//
//#pragma  mark ---------  UIImagePickerControllerDelegate
//
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
//     UIImage *userImage = [self fixOrientation:(UIImage *)info[UIImagePickerControllerEditedImage]];
//    // UIImagePickerControllerOriginalImage
//
//    // 图片缩放
//    userImage = [self scaleImage:userImage toScale:0.3];
//
//    //    照片上传
//    // [self upDateHeadIcon:userImage];
//    //保存图片 保存到沙河
//    //   [self saveImage:userImage name:@"touxiang"];
//
//    // QrCodeableViewCell *qrCodCell = [tableView dequeueReusableCellWithIdentifier:qrCodID];
//
////    NSIndexPath *inde = [NSIndexPath indexPathForRow:0 inSection:0];
////    IconInformationCell *iconcell =   (IconInformationCell *)[self.informationTableview cellForRowAtIndexPath:inde];
////    iconcell.IconImageView.image = userImage;
//
//
//    if ([self.panduanStr isEqualToString:@"1"]) {
//        self.zhengmianImageView.hidden = NO;
//          self.zhengmianImageView.image = userImage;
//    } else {
//
//        self.fanmianImageview.hidden = NO;
//        self.fanmianImageview.image = userImage;
//
//
//
//    }
//
//
//    //往配图相册view里面添加图片
//    [picker dismissViewControllerAnimated:YES completion:nil];
//}
//
////- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
////    //    修正照片方向(手机转90度方向拍照)
////    UIImage *userImage = [self fixOrientation:[editingInfo objectForKey:@"UIImagePickerControllerOriginalImage"]];
////
////    // 图片缩放
////    userImage = [self scaleImage:userImage toScale:0.3];
////
////    //    照片上传
////   // [self upDateHeadIcon:userImage];
////    //保存图片 保存到沙河
////  //   [self saveImage:userImage name:@"touxiang"];
////
////    //往配图相册view里面添加图片
////    [picker dismissViewControllerAnimated:YES completion:nil];
////}
//
//
////修正照片方向(手机转90度方向拍照)
//- (UIImage *)fixOrientation:(UIImage *)aImage {
//
//    // No-op if the orientation is already correct
//    if (aImage.imageOrientation == UIImageOrientationUp)
//        return aImage;
//
//    // We need to calculate the proper transformation to make the image upright.
//    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
//    CGAffineTransform transform = CGAffineTransformIdentity;
//
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationDown:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
//            transform = CGAffineTransformRotate(transform, M_PI);
//            break;
//
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
//            transform = CGAffineTransformRotate(transform, M_PI_2);
//            break;
//
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
//            transform = CGAffineTransformRotate(transform, -M_PI_2);
//            break;
//        default:
//            break;
//    }
//
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationUpMirrored:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//        default:
//            break;
//    }
//
//    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
//                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
//                                             CGImageGetColorSpace(aImage.CGImage),
//                                             CGImageGetBitmapInfo(aImage.CGImage));
//    CGContextConcatCTM(ctx, transform);
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            // Grr...
//            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
//            break;
//
//        default:
//            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
//            break;
//    }
//
//    // And now we just create a new UIImage from the drawing context
//    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
//    UIImage *img = [UIImage imageWithCGImage:cgimg];
//    CGContextRelease(ctx);
//    CGImageRelease(cgimg);
//    return img;
//}
//
////缩放图片
//- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
//{
// UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
//    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
//    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    NSLog(@"%@",NSStringFromCGSize(scaledImage.size));
//    return scaledImage;
//}
//
////保存照片到沙盒路径(保存)
//- (void)saveImage:(UIImage *)image name:(NSString *)iconName
//{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//    //写入文件
//    NSString *icomImage = iconName;
//    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", icomImage]];
//    // 保存文件的名称
//    //    [[self getDataByImage:image] writeToFile:filePath atomically:YES];
//    [UIImagePNGRepresentation(image) writeToFile: filePath  atomically:YES];
//}
//
////上传图片
//- (void)upDateHeadIcon:(UIImage *)photo
//{
//    if (photo == nil) {
//        return;
//    }
//
//
//}
//
//
//
//
//-(NSString *)convertToJsonData:(NSDictionary *)dict {
//
//    NSError *error;
//
//    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
//
//    NSString *jsonString;
//
//    if (!jsonData) {
//        NSLog(@"%@",error);
//    }else{
//        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
//    }
//    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
//    NSRange range = {0,jsonString.length};
//
//    //去掉字符串中的空格
//    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
//    NSRange range2 = {0,mutStr.length};
//
//    //去掉字符串中的换行符
//    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
//
//    return mutStr;
//
//}
//
//
//
//
//
//@end
//
